package com.yzh.sort;

import java.util.Arrays;

/**
 * @author 于振晗
 * @title: BubbleSortTest
 * @description: TODO 冒泡排序
 * @date 2020年08月18日
 * @path com.yzh.sort;
 */
public class BubbleSortTest {
    public static void main(String[] args) {
        int [] arr = {5,4,3,2,1};
        int[] arr2 = Arrays.copyOf(arr, arr.length);
        System.out.println(Arrays.toString(arr));
        for (int i = 0; i < arr.length-1; i++) {
            for (int j = 0; j < arr.length-1-i; j++) {
                if(arr[j]>arr[j+1]){
                    int temp = arr[j+1];
                    arr[j+1] = arr[j];
                    arr[j] = temp;
                }
            }
        }
        System.out.println(Arrays.toString(arr));

        Arrays.sort(arr2);
        System.out.println(Arrays.toString(arr2));
    }
}
